package bjfuwjx.exp4;

import javax.swing.*;
import java.awt.*;
import java.util.ConcurrentModificationException;
import java.util.concurrent.CopyOnWriteArrayList;

public class MyPanel extends JPanel {
    public CopyOnWriteArrayList<Ball> list1,list2;
    public CopyOnWriteArrayList<ShootingBall> list3;
    public MyPanel(CopyOnWriteArrayList<Ball> list1, CopyOnWriteArrayList<Ball> list2,CopyOnWriteArrayList<ShootingBall> list3){
        this.list1=list1;
        this.list2=list2;
        this.list3=list3;
        this.setSize(1000,700);
    }
    public void add1(Ball ball){
        this.list1.add(ball);
    }
    public void add2(Ball ball){
        this.list2.add(ball);
    }
    public void add3(ShootingBall shootball) {
        this.list3.add(shootball);
    }

    @Override
    protected void paintComponent(Graphics g) throws ConcurrentModificationException {
        super.paintComponent(g);
        Graphics2D graphics2D=(Graphics2D) g;
        if (list1.size()!=0) {
            for (Ball ball : list1) {
                graphics2D.setColor(Color.BLUE);
                graphics2D.fill(ball.shape());
            }
        }
        if (list2.size()!=0) {
            for (Ball ball:list2) {
                graphics2D.setColor(Color.BLUE);
                graphics2D.fill(ball.shape());
            }
        }
        if (list3.size()!=0) {
            for (ShootingBall shoot:list3) {
                graphics2D.setColor(Color.RED);
                graphics2D.fill(shoot.shape());
            }
        }
    }
}
